package com.powernode.boss.tools;


import ch.qos.logback.core.joran.conditional.IfAction;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.TimeUnit;


public class RedisHelper {

    private StringRedisTemplate template = null;
    private ValueOperations<String,String> valueOperations = null;
    private HashOperations<String, Object, Object> hashOperations = null;

    public RedisHelper(StringRedisTemplate stringRedisTemplate) {
        template=stringRedisTemplate;
        valueOperations = stringRedisTemplate.opsForValue();
        hashOperations = stringRedisTemplate.opsForHash();
    }
    //储存hash类型,设置过期时间
    public boolean setHashAll(String key, Map<String,String> data,
                                TimeUnit timeUnit,Integer timeout){
        if (timeout >0 ){
            hashOperations.putAll(key,data);
            return template.expire(key, timeout, timeUnit);
        }
        return false;


    }



}
